using System;
using System.Collections;
using System.Data;
using CE.Database;
/// <summary>
/// Summary description for UserProfileDB
/// </summary>
/// 
namespace CE.PersonalAccident
{
    public class PersonalAccidentDB
    {
        public PersonalAccidentDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public PersonalAccident GetPersonalAccident(Int64 PAID)
        {
            MyDatabase _Db = new MyDatabase();
            string _spName = "[sprocPAInsuranceSelectSingleItem]";
            PersonalAccident _result = null;
            DataTable _dt;
            SortedList _sPara = new SortedList();

            _sPara.Add("@PAID", PAID);

            _dt = _Db.GetDataTableBySP(_spName, _sPara);

            if (_dt != null && _dt.Rows.Count > 0)
            {
                _result = new PersonalAccident();
                _result = FillDataRecord(_dt);
            }

            return _result;
        }

        public Int64 Insert(PersonalAccident personacc)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocPAInsuranceInsertUpdateSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@PAID", personacc.PAID);
            _sPara.Add("@CoverType", personacc.CoverType);
            //_sPara.Add("@DeathAmount", personacc.DeathAmount); //Sakthi on 05 Apr 2011
            _sPara.Add("@DOB", personacc.DOB);
            _sPara.Add("@Occupation", personacc.Occupation);
            _sPara.Add("@SPDOB", personacc.SPDOB);
            _sPara.Add("@SPOccupation", personacc.SPOccupation);
            _sPara.Add("@NoOfChild", personacc.NoOfChild);
            _sPara.Add("@InsCommentDate", personacc.InsCommentDate);
            _sPara.Add("@IsAcceptTerm", personacc.IsAcceptTerm);
            //Start - Comment on 08/06/2010 Sakthi
            _sPara.Add("@SurName", personacc.SurName);
            _sPara.Add("@PhoneNo", personacc.PhoneNo);
            _sPara.Add("@Email", personacc.Email);
            //End
            _sPara.Add("@ViewedDetailId", personacc.ViewedDetailId);
            _sPara.Add("@Status", personacc.Status);
            _sPara.Add("@RefCEUserID", personacc.RefCEUserId);
            _sPara.Add("@Info1", personacc.Info1);
            _sPara.Add("@Info2", personacc.Info2);
            _sPara.Add("@Info3", personacc.Info3);
            _sPara.Add("@Info4", personacc.Info4);
            _sPara.Add("@Info5", personacc.Info5);
            _sPara.Add("@Info6", personacc.Info6);
            _sPara.Add("@Info7", personacc.Info7);
            _sPara.Add("@Info8", personacc.Info8);
            _sPara.Add("@Info9", personacc.Info9);
            _sPara.Add("@Info10", personacc.Info10);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete()
        {
            return true;
        }

        public Int64 UpdatePAContactInfo(Int64 PAid, string SurName, string PhoneNo, string Email)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocPAInsuranceUpdateContactInfo]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@PAID", PAid);
            _sPara.Add("@SurName", SurName);
            _sPara.Add("@PhoneNo", PhoneNo);
            _sPara.Add("@Email", Email);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        private PersonalAccident FillDataRecord(DataTable myDataTable)
        {
            PersonalAccident myPA = new PersonalAccident();
            myPA.PAID = Convert.ToInt64(myDataTable.Rows[0]["PAID"].ToString());
            myPA.CoverType = myDataTable.Rows[0]["CoverType"].ToString();
            //myPA.DeathAmount = Convert.ToSingle(myDataTable.Rows[0]["DeathAmount"].ToString()); //Sakthi on 05 Apr 2011
            myPA.DOB = Convert.ToDateTime(myDataTable.Rows[0]["DOB"].ToString());
            myPA.Occupation = myDataTable.Rows[0]["Occupation"].ToString();
            myPA.SPDOB = Convert.ToDateTime(myDataTable.Rows[0]["SPDOB"].ToString());
            myPA.SPOccupation = myDataTable.Rows[0]["SPOccupation"].ToString();
            myPA.NoOfChild = Convert.ToInt16(myDataTable.Rows[0]["NoOfChild"].ToString());
            myPA.InsCommentDate = Convert.ToDateTime(myDataTable.Rows[0]["InsCommentDate"].ToString());
            myPA.IsAcceptTerm = Convert.ToBoolean(myDataTable.Rows[0]["IsAcceptTerm"].ToString());
            myPA.Status = Convert.ToBoolean(myDataTable.Rows[0]["Status"].ToString());
            //Start - Comment on 08/06/2010 Sakthi
            myPA.SurName = myDataTable.Rows[0]["SurName"].ToString();
            myPA.PhoneNo = myDataTable.Rows[0]["PhoneNo"].ToString();
            myPA.Email = myDataTable.Rows[0]["Email"].ToString();
            //End
            myPA.CreatedDate = Convert.ToDateTime(myDataTable.Rows[0]["CreatedDate"].ToString());
            myPA.ModifiedDate = Convert.ToDateTime(myDataTable.Rows[0]["ModifiedDate"].ToString());
            return myPA;
        }
    }
}